<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script type="text/javascript">
		function clickMe(){
			var num = parseInt(document.getElementById('numId').value);
			var resultSpan = document.getElementById("resultId");
			if(isNaN(num)){
				resultSpan.innerHTML = "<span style='color: red;'>您输入的不是一个数字</span>";
				return;
			}
			if(num < 0){
				resultSpan.innerHTML = "<span style='color: red;'>负数没有阶乘</span>";
				return;
			}
			if(num == 0){
				resultSpan.innerHTML = 1;
			}else{
				var sum=1;
				for(var i = 1; i <= num; i++){
					sum *= i;
				}
			}
			resultSpan.innerHTML = sum;
		}
		</script>
	</head>
	<body>
			<input type="text" id="numId"/>
			<input type="button" value="阶乘" onclick="clickMe()"/>
			<span>=</span>
			<span id="resultId"></span>
		</tr>
	</body>
</html>
